package com.holyn.guofang.presenter.distinguish;

import com.holyn.guofang.model.webhttp.RetrofitManager;
import com.holyn.guofang.model.webhttp.observable.BrandObservable;
import com.holyn.guofang.model.webhttp.wo.BrandBulletinWo;
import com.holyn.guofang.model.webhttp.wo.BrandGoodsWo;
import com.holyn.guofang.model.webhttp.wo.BrandInfoWo;
import com.holyn.guofang.model.webhttp.wo.BrandProcessWo;
import com.holyn.guofang.presenter.BaseView;

import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;

/**
 * Created by Holyn on 2017/7/19.
 */

public class SearchResultDetailPresenter extends SearchResultDetailContract.Presenter{

    private BrandObservable brandObservable;
    private SearchResultDetailContract.DetailView detailView;
    private SearchResultDetailContract.NoticeView noticeView;
    private SearchResultDetailContract.ProcessView processView;
    private SearchResultDetailContract.ServiceView serviceView;

    public SearchResultDetailPresenter(BaseView baseView) {
        super(baseView);
        brandObservable = RetrofitManager.getCommonObservable(BrandObservable.class);
    }

    @Override
    public void addDetailView(SearchResultDetailContract.DetailView detailView) {
        this.detailView = detailView;
    }

    @Override
    public void addNoticeView(SearchResultDetailContract.NoticeView noticeView) {
        this.noticeView = noticeView;
    }

    @Override
    public void addProcessView(SearchResultDetailContract.ProcessView processView) {
        this.processView = processView;
    }

    @Override
    public void addServiceView(SearchResultDetailContract.ServiceView serviceView) {
        this.serviceView = serviceView;
    }

    @Override
    public void postTmInfbyMarkNo(int requestAction, String MarkNo, Integer MarkClass) {
        getCommonObservable(requestAction, brandObservable.getTmInfbyMarkNo(MarkNo, MarkClass))
                .subscribe(new Consumer<BrandInfoWo>() {
                    @Override
                    public void accept(@NonNull BrandInfoWo brandInfoWo) throws Exception {
                        detailView.responseSuccess(requestAction, brandInfoWo);
                    }
                });
    }

    @Override
    public void postBulletinInfo(int requestAction, String MarkNo, Integer MarkClass) {
        getCommonObservable(requestAction, brandObservable.getBulletinInfo(MarkNo, MarkClass))
                .subscribe(new Consumer<BrandBulletinWo>() {
                    @Override
                    public void accept(@NonNull BrandBulletinWo brandBulletinWo) throws Exception {
                        noticeView.responseSuccess(requestAction, brandBulletinWo);
                    }
                });
    }

    @Override
    public void postMarkProcess(int requestAction, String MarkNo, Integer MarkClass) {
        getCommonObservable(requestAction,brandObservable.getMarkProcess(MarkNo,MarkClass))
                .subscribe(new Consumer<BrandProcessWo>() {
                    @Override
                    public void accept(@NonNull BrandProcessWo brandProcessWo) throws Exception {
                        processView.responseSuccess(requestAction, brandProcessWo);
                    }
                });
    }

    @Override
    public void postMarkGoods(int requestAction, String MarkNo, Integer MarkClass) {
        getCommonObservable(requestAction, brandObservable.getMarkGoods(MarkNo, MarkClass))
                .subscribe(new Consumer<BrandGoodsWo>() {
                    @Override
                    public void accept(@NonNull BrandGoodsWo brandGoodsWo) throws Exception {
                        serviceView.responseSuccess(requestAction, brandGoodsWo);
                    }
                });
    }
}
